package security.web.controller;

import java.util.concurrent.atomic.AtomicLong;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Application Lifecycle Listener implementation class WebAppSessionListener
 *
 */
public class WebAppSessionListener implements HttpSessionListener {

	private final AtomicLong currentSessionCount = new AtomicLong();
    /**
     * Default constructor. 
     */
    public WebAppSessionListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent sessionEvent) {
    	long count = currentSessionCount.incrementAndGet();
    	sessionEvent.getSession().getServletContext().log("当前访问人数：" + count);
    }

	/**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent sessionEvent) {
    	long count = currentSessionCount.decrementAndGet();
    	sessionEvent.getSession().getServletContext().log("当前访问人数：" + count);
    }
	
}
